package video.com.config;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import video.com.interceptor.UserInfoInterceptor;

@Component
public class InterceptorConfiguration implements WebMvcConfigurer {

    @Value("${file.path}")
    private String filePath;

    /**
     * 对资源类型路径添加映射
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){
        registry.addResourceHandler("/image/**").addResourceLocations("file:" + filePath);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInfoInterceptor())
                .addPathPatterns("/video/**")
                .excludePathPatterns("/video/getVideoInfo/**","/video/tourist/**","/video/userCommend/**","/video/videoCommend/**","/video/tag/getTag/**");
    }
}
